import { reactive } from 'vue'
import { defineStore } from 'pinia'
import { GiteeSettings } from "@/data/entity/GiteeSettings";
import { get, set } from '@/data/persistent/localStorage'
import { ACCOUNT_PREFIX } from "@/data/constants/Constants";

export const useAccountStore = defineStore('account', () => {
    const gitee:GiteeSettings = reactive(GiteeSettings.parse(get(ACCOUNT_PREFIX + ACCOUNT_NAME)))

    function getGitee(){
        return JSON.parse(JSON.stringify(gitee))
    }

    function setGitee(giteeSettings:GiteeSettings){
        Object.assign(gitee, giteeSettings)
        set(ACCOUNT_PREFIX + ACCOUNT_NAME, gitee)
    }

    function reset(){
        setGitee(new GiteeSettings())
    }

    return { getGitee, setGitee, reset }
})

const ACCOUNT_NAME = 'gitee'
